package com.league.zjxn.main.mine

import android.os.Bundle
import com.league.zjxn.R
import com.league.zjxn.jetpack.vmodel.UserViewModel
import com.league.zjxn.main.home.HomeTrendFragment
import com.league.zjxn.main.mine.adapter.EnterpriseApproveAdapter
import com.league.zjxn.main.mine.adapter.FollowEnterpriseAdapter
import com.league.zjxn.main.mine.adapter.FollowProjectAdapter
import com.module.lemlin.http.Status
import com.module.lemlin.owner.OwnerViewModeFragment
import kotlinx.android.synthetic.main.fragment_mine_approve.*

class MineApproveFragment : OwnerViewModeFragment<UserViewModel>() {

    companion object {
        private const val KEY_APPROVE_STATUS = "KEY_APPROVE_STATUS"
        fun newInstance(status: Int): MineApproveFragment {
            val bundle: Bundle = Bundle().apply {
                putInt(KEY_APPROVE_STATUS, status)
            }
            return MineApproveFragment().apply {
                arguments = bundle
            }
        }
    }

    private val mEnterpriseApproveAdapter = EnterpriseApproveAdapter()

    private val mStatus: String? by lazy {
        val status = arguments?.getInt(KEY_APPROVE_STATUS)
        if (status == 1) "9" else if (status == 2) "5" else if (status == 3) "6" else null
    }

    override fun viewModel(): UserViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.fragment_mine_approve

    override fun initView() {
        rvMineApproveBody.adapter = mEnterpriseApproveAdapter
    }

    override fun initData() {
        viewModel.userEnterpriseApprove(mStatus)
    }

    override fun initViewMode() {
        viewModel.enterpriseApproveLiveData.observe(viewLifecycleOwner, { response ->
            if (response.status != Status.SUCCESS) {
                return@observe
            }
            val data = response.data?.data?.data
                ?: return@observe
            mEnterpriseApproveAdapter.setNewInstance(data)
        })
    }

}